﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace chlnge
{
    class Measure
    {
        private int measureId;
        private string measureName;

        public Measure(int measureId, string measureName)
        {
            this.measureId = measureId;
            this.measureName = measureName;
        }

        private static string GenerateQuerry()
        {
            return "Select * From measures";
        }

        public int MeasureId
        {
            get
            {
                return measureId;
            }
            set
            {
                measureId = value;
            }
        }

        public string MeasureName
        {
            get
            {
                return measureName;
            }
            set
            {
                measureName = value;
            }
        }

        public static List<Measure> GetMeasures() 
        {
            string connString = "Server = localhost; Database = productsinformation; Uid = root; password = valerieva";

            MySqlConnection conn = new MySqlConnection(connString);
            List<Measure> measures = new List<Measure>();
            MySqlCommand command = conn.CreateCommand();
            command.CommandText = GenerateQuerry();

            using(conn)
            {
                conn.Open();
                MySqlDataReader reader = command.ExecuteReader();
                using (reader)
                {
                    while (reader.Read())
                    {
                        measures.Add(new Measure((int)reader["measureId"], (string)reader["measureName"]));
                    }
                }
            }
            return measures;
        }
    }
}
